----------------------------------------------------------------------
-- 	Leatrix Plus 4.2.16
-- 	Last updated: 18th September 2011
----------------------------------------------------------------------

-- 	Create tables to store configuration
	if not LeaPlusOptionsDB then LeaPlusOptionsDB = {} end
	local LeaPlusOptionsLC = {}

--	Initialise variables
	local r, g, b = 1.0, 0.85, 0.0
	local orig_OpenAllBags = OpenAllBags;
	local orig_CloseAllBags = CloseAllBags;
	local Leatrix_Script = UIErrorsFrame:GetScript('OnEvent')
	local _, LeaPlusPlayerClass = UnitClass("player");

--	Dungeon spam array
	local LeaPlusSpamArray = {"interrupted", "taunt", "activate", "mind freeze", "rebuke", "bash", "pummel", "silence", "counterspell", "wind shear", "spell lock", "salvation"}
	local LeaPlusSpamTip = "\n"
	for k,v in pairs(LeaPlusSpamArray) do
		LeaPlusSpamTip = LeaPlusSpamTip .. "\n" .. LeaPlusSpamArray[k]
	end

--	Error array
	local LeaPlusErrArray = {"inventory is full", "quest log is full", "you can not initiate", "player can not be kicked", "players cannot be kicked"}
	local LeaPlusErrTip = "\n"
	for k,v in pairs(LeaPlusErrArray) do
		LeaPlusErrTip = LeaPlusErrTip .. "\n" .. LeaPlusErrArray[k]
	end

--	Create frame so we can watch events
	local frame = CreateFrame("FRAME", "Leatrix_Plus");
	frame:RegisterEvent("ADDON_LOADED");
	frame:RegisterEvent("PLAYER_LOGIN");
	frame:RegisterEvent("PLAYER_LOGOUT");

----------------------------------------------------------------------
--	Chat filters
----------------------------------------------------------------------

--	Party interrupt filter
	local function LeaPlusInterruptFilter(arg1,arg2,msg,arg4)
		if not (IsInInstance() == nil) and (UnitAffectingCombat("player")) then
			for k,v in pairs(LeaPlusSpamArray) do
				if string.lower(msg):find(v) then
					return true
				end
			end
		end
	end

--	Duel spam filter
	local function LeaPlusDuelFilter(arg1,arg2,msg)
		-- Do nothing if your name is mentioned
		if (UnitName("player")) and (msg:find(UnitName("player"))) then
			return
		end
		-- Block messages involving duels
		if (msg:find("has defeated")) then return true end
		if (msg:find("has fled from")) then return true	end
	end

--	Dual spec filter
	local function LeaPlusTalentFilter(arg1,arg2,msg)
		-- Block messages involving dual spec
		if (msg:find(string.gsub(ERR_LEARN_ABILITY_S:gsub('%.', '%.'), '%%s', '(.*)'))) then return true end
		if (msg:find(string.gsub(ERR_LEARN_SPELL_S:gsub('%.', '%.'), '%%s', '(.*)'))) then return true end
		if (msg:find(string.gsub(ERR_SPELL_UNLEARNED_S:gsub('%.', '%.'), '%%s', '(.*)'))) then return true end
	end

----------------------------------------------------------------------
--	Functions
----------------------------------------------------------------------

-- 	Show button tooltips
	local function ShowTooltip(self)
		if self.tiptext then
			GameTooltip:SetOwner(self, "ANCHOR_TOP")
			GameTooltip:SetText(self.tiptext, nil, nil, nil, nil, true)
		end
	end

-- 	Hide button tooltips
	local function HideTooltip() 
		GameTooltip:Hide() 
	end

--	Check if a player name is in your friends list
	local function LeaPlusFriendCheck(LeaListName)
		for i = 1, GetNumFriends() do
			if (LeaListName == GetFriendInfo(i)) then
				return true
			end
		end
		return false;
	end

--	Lock and dim invalid checkboxes
	local function LeaPlusSetDim()

		-- Quest detail font slider lockout
		if LeaPlusOptionsLC["LeaPlusQuestFont"] == "Off" then
			LeaPlusQuestSize:Disable()
			LeaPlusQuestSize:SetAlpha(0.3)
		else
			LeaPlusQuestSize:Enable()
			LeaPlusQuestSize:SetAlpha(1.0)
		end

		-- Automatically accept quest lockout
		if LeaPlusOptionsLC["LeaPlusQAccHead"] == "Off" then
			LeaPlusQAccAll:Disable()
			LeaPlusQAccAll:SetAlpha(0.3)
			LeaPlusQAccDaily:Disable()
			LeaPlusQAccDaily:SetAlpha(0.3)
		else
			LeaPlusQAccAll:Enable()
			LeaPlusQAccAll:SetAlpha(1.0)
			if LeaPlusOptionsLC["LeaPlusQAccAll"] == "Off" then
				LeaPlusQAccDaily:Enable()
				LeaPlusQAccDaily:SetAlpha(1.0)
			else
				LeaPlusQAccDaily:Disable()
				LeaPlusQAccDaily:SetAlpha(0.3)
			end
		end

		-- Automatically repair lockout
		if LeaPlusOptionsLC["LeaPlusRepairSelf"] == "Off" then
			LeaPlusRepairGuild:Disable()
			LeaPlusRepairGuild:SetAlpha(0.3)
			LeaPlusRepairForce:Disable()
			LeaPlusRepairForce:SetAlpha(0.3)
		else
			LeaPlusRepairGuild:Enable()
			LeaPlusRepairGuild:SetAlpha(1.0)
			if LeaPlusOptionsLC["LeaPlusRepairGuild"] == "Off" then
				LeaPlusRepairForce:Disable()
				LeaPlusRepairForce:SetAlpha(0.3)
			else
				LeaPlusRepairForce:Enable()
				LeaPlusRepairForce:SetAlpha(1.0)
			end
		end

	end

--	Quest size update (when changing slider)
	local function LeaPlusQuestSizeUpdate()
		if LeaPlusOptionsLC["LeaPlusQuestFont"] == "On" then
			SystemFont_Med1:SetFont(SystemFont_Med1:GetFont(), LeaPlusOptionsLC["LeaPlusQuestSize"], nil);
			SystemFont_Med2:SetFont(SystemFont_Med2:GetFont(), LeaPlusOptionsLC["LeaPlusQuestSize"]+1, nil);	
			QuestFont_Shadow_Huge:SetFont(QuestFont_Shadow_Huge:GetFont(), (LeaPlusOptionsLC["LeaPlusQuestSize"]+6), nil);
		elseif LeaPlusOptionsLC["LeaPlusQuestFont"] == "Off" then
			SystemFont_Med1:SetFont(SystemFont_Med1:GetFont(), 12, nil);
			SystemFont_Med2:SetFont(SystemFont_Med2:GetFont(), 13, nil);	
			QuestFont_Shadow_Huge:SetFont(QuestFont_Shadow_Huge:GetFont(), 18, nil);
		end
	end

----------------------------------------------------------------------
--	Quest Levels
----------------------------------------------------------------------

	-- Create table for tags (only needed if quest type tags are used)
	local _, LeaPlusQuestTags = {}, {Elite = "+", Group = "G", Dungeon = "D", Raid = "R", PvP = "P", Daily = "!", Heroic = "H", Repeatable = "?"}

	-- Show quest levels
	local function LeaPlusShowQuestLevels()
		if LeaPlusOptionsLC["LeaPlusQuestLevel"] == "On" then
			local buttons = QuestLogScrollFrame.buttons
			local LeaPlusQuestButtons = #buttons
			local LeaPlusScrollOffset = HybridScrollFrame_GetOffset(QuestLogScrollFrame)
			local LeaPlusQuestEntries, _ = GetNumQuestLogEntries()

			-- Go through quest log
			for i = 1, LeaPlusQuestButtons do
				local LeaPlusQuestIndex = i + LeaPlusScrollOffset
				local LeaPlusQuestTitle = buttons[i]
				if LeaPlusQuestIndex <= LeaPlusQuestEntries then
					local title, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily = GetQuestLogTitle(LeaPlusQuestIndex)
					-- Add quest type
					if not isHeader or title then
						if not suggestedGroup or suggestedGroup == 0 then suggestedGroup = nil end
						title = string.format("[%s%s%s%s] %s", level, questTag and LeaPlusQuestTags[questTag] or "", isDaily and LeaPlusQuestTags.Daily or "",suggestedGroup or "", title), questTag, isDaily, isComplete
					end
					-- Show quest title with level
					if not isHeader then
						LeaPlusQuestTitle:SetText(title)
						QuestLogTitleButton_Resize(LeaPlusQuestTitle)
					end
				end
			end
		end
	end

	hooksecurefunc('QuestLog_Update', LeaPlusShowQuestLevels)
	QuestLogScrollFrameScrollBar:HookScript('OnValueChanged', LeaPlusShowQuestLevels)

----------------------------------------------------------------------
--	Hunter pet icon
----------------------------------------------------------------------

	local function LeaPlusShowMendPet()

		local LeaPlusMendPet, _, LeaPlusMendTexPath = GetSpellInfo(136)

		-- Create pet icon frame
		local LeaPlusPetFrame = CreateFrame("Frame","LeaPlusPetFrame",PetFrame)
		LeaPlusPetFrame:SetFrameStrata("BACKGROUND")
		LeaPlusPetFrame:SetWidth(20)
		LeaPlusPetFrame:SetHeight(20)
		LeaPlusPetFrame:ClearAllPoints()
		LeaPlusPetFrame:SetPoint("LEFT", PetFrame, "RIGHT", 0, -6)

		-- Create cooldown
		local cooldown = CreateFrame("cooldown", nil, LeaPlusPetFrame, "CooldownFrameTemplate")
		cooldown:SetPoint("CENTER", 0, -1)
		cooldown:SetWidth(20)
		cooldown:SetHeight(20)
		cooldown:Hide()

		-- Create texture from Mend Pet spell ID
		local LeaPlusPetMendTex = LeaPlusPetFrame:CreateTexture(nil,"BACKGROUND")
		LeaPlusPetMendTex:SetTexture(LeaPlusMendTexPath)
		LeaPlusPetMendTex:SetAllPoints(LeaPlusPetFrame)
		LeaPlusPetFrame.texture = LeaPlusPetMendTex
		
		-- Icon script
		LeaPlusPetFrame:SetScript("OnEvent", function(frame,event,arg1)

			-- Pet icon
			if arg1 == "pet" and LeaPlusOptionsLC["LeaPlusPetIcon"] == "On" then
				LeaPlusPetFrame:Hide()
				local LeaPlusPetBuff,_,_,LeaPlusPetDuration,LeaPlusPetExpire,LeaPlusPetStart
				for i=1,16 do
					LeaPlusPetBuff, _, _, _, _, LeaPlusPetDuration, LeaPlusPetExpire, _, _ = UnitBuff("pet",i)

					-- No buff
					if not LeaPlusPetBuff then
						break

					-- Show Mend Pet icon
					elseif LeaPlusPetBuff == LeaPlusMendPet then
						LeaPlusPetStart = LeaPlusPetExpire - LeaPlusPetDuration
						CooldownFrame_SetTimer(cooldown, LeaPlusPetStart, LeaPlusPetDuration, 1)
						LeaPlusPetFrame:Show()
					end
				end
			end

		end);
		LeaPlusPetFrame:Hide()

	end

----------------------------------------------------------------------
--	Honorable Kills stat
----------------------------------------------------------------------

	local function LeaPlusShowHkFunc()

		-- 	Create heading
			local PVPT1 = PVPFrame:CreateFontString(nil, 'ARTWORK', "GameFontNormal")
			PVPT1:SetPoint("TOPRIGHT",-80,-38)
			PVPT1:SetText("HKS")

		-- 	Create placeholder for stat
			local PVPT2 = PVPFrame:CreateFontString(nil, 'ARTWORK', "GameFontHighlight")
			PVPT2:SetPoint("LEFT",PVPT1,"LEFT",30,0)

			PVPFrame:HookScript("OnShow", function()

				if LeaPlusOptionsLC["LeaPlusShowHks"] == "On" then

					-- Get current number of honorable kills from stats
					hks = GetStatistic(588)

					-- Move honor text to the left
					PVPFrameCurrency:ClearAllPoints();
					PVPFrameCurrency:SetPoint("TOPLEFT",PVPFrame,"TOPLEFT",110,-20)

					-- Show HKs to the right
					PVPT2:SetText(hks)
					PVPT1:Show();
					PVPT2:Show();

				else

					-- Move honor back to the middle
					PVPFrameCurrency:ClearAllPoints();
					PVPFrameCurrency:SetPoint("TOP",PVPFrame,"TOP",0,-20)

					-- Don't show stat
					PVPT1:Hide();
					PVPT2:Hide();

				end

			end)

	end

----------------------------------------------------------------------
--	Do It Now!
----------------------------------------------------------------------

--	The Do It Now bit
	local function DoItNow(frame)

		-- Bag automation
		function OpenAllBags(...)
			if LeaPlusOptionsLC["LeaPlusDisBP"] == "On" then
				return
			else
				return orig_OpenAllBags(...);
			end
		end

		function CloseAllBags(...)
			if LeaPlusOptionsLC["LeaPlusDisBP"] == "On" then
				return
			else
				return orig_CloseAllBags(...);
			end
		end

		-- Hunter
		if LeaPlusPlayerClass == "HUNTER" then

			-- Mend Pet icon
			if LeaPlusOptionsLC["LeaPlusPetIcon"] == "On" then
				LeaPlusPetFrame:RegisterEvent("UNIT_AURA");
			else
				LeaPlusPetFrame:UnregisterEvent("UNIT_AURA");
				LeaPlusPetFrame:Hide();
			end

		end

		-- Automatic resurrection
		if LeaPlusOptionsLC["LeaPlusNormalRes"] == "On" then
			frame:RegisterEvent("RESURRECT_REQUEST");
		else
			frame:UnregisterEvent("RESURRECT_REQUEST");
		end

		-- Hide gryphons
		if LeaPlusOptionsLC["LeaPlusGryphons"] == "On" then
			MainMenuBarLeftEndCap:Hide();
			MainMenuBarRightEndCap:Hide();
		else
			MainMenuBarLeftEndCap:Show();
			MainMenuBarRightEndCap:Show();
		end

		-- Set zoom out level to max
		if LeaPlusOptionsLC["LeaPlusZoomOut"] == "On" then
			SetCVar("CameraDistanceMax", "50")
		else
			SetCVar("CameraDistanceMax", "15")
		end

		-- Don't confirm loot rolls
		if LeaPlusOptionsLC["LeaPlusLootNoConfirm"] == "On" then
			frame:RegisterEvent("CONFIRM_LOOT_ROLL");
			frame:RegisterEvent("CONFIRM_DISENCHANT_ROLL");
			frame:RegisterEvent("LOOT_BIND_CONFIRM");
		else
			frame:UnregisterEvent("CONFIRM_LOOT_ROLL");
			frame:UnregisterEvent("CONFIRM_DISENCHANT_ROLL");
			frame:UnregisterEvent("LOOT_BIND_CONFIRM");
		end

		-- Block duel messages
		if LeaPlusOptionsLC["LeaPlusDuelMessage"] == "On" then
			ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", LeaPlusDuelFilter)
		else
			ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", LeaPlusDuelFilter)
		end

		-- Block interrupt messages
		if LeaPlusOptionsLC["LeaPlusInterruptMsg"] == "On" then
			ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY", LeaPlusInterruptFilter)
			ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY", LeaPlusInterruptFilter)
			ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY_LEADER", LeaPlusInterruptFilter)
		else
			ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SAY", LeaPlusInterruptFilter)
			ChatFrame_RemoveMessageEventFilter("CHAT_MSG_PARTY", LeaPlusInterruptFilter)
			ChatFrame_RemoveMessageEventFilter("CHAT_MSG_PARTY_LEADER", LeaPlusInterruptFilter)
		end

		-- Block dual-spec spam
		if LeaPlusOptionsLC["LeaPlusDualSpec"] == "On" then
			frame:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED");
			ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", LeaPlusTalentFilter)
		else
			frame:UnregisterEvent("ACTIVE_TALENT_GROUP_CHANGED");
			ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", LeaPlusTalentFilter)
		end

		-- Disable death effect
		if LeaPlusOptionsLC["LeaPlusDeathEffect"] == "On" then
			SetCVar("ffxDeath", "0")
		else
			SetCVar("ffxDeath", "1")
		end

		-- Disable netherworld effect
		if LeaPlusOptionsLC["LeaPlusNetherEffect"] == "On" then
			SetCVar("ffxNetherWorld", "0")
		else
			SetCVar("ffxNetherWorld", "1")
		end

		-- Disable full-screen glow
		if LeaPlusOptionsLC["LeaPlusGlowEffect"] == "On" then
			SetCVar("ffxGlow", "0")
		else
			SetCVar("ffxGlow", "1")
		end

		-- Disable special effects
		if LeaPlusOptionsLC["LeaPlusSpecialEffect"] == "On" then
			SetCVar("ffxSpecial", "0")
		else
			SetCVar("ffxSpecial", "1")
		end

		-- Block duels
		if LeaPlusOptionsLC["LeaPlusDeclineDuel"] == "On" then
			frame:RegisterEvent("DUEL_REQUESTED");
		else
			frame:UnregisterEvent("DUEL_REQUESTED");
		end

		-- Block guild petitions
		if LeaPlusOptionsLC["LeaPlusClosePetition"] == "On" then
			frame:RegisterEvent("PETITION_SHOW");
		else
			frame:UnregisterEvent("PETITION_SHOW");
		end

		-- Block party invites
		if LeaPlusOptionsLC["LeaPlusDeclineParty"] == "On" then
			frame:RegisterEvent("PARTY_INVITE_REQUEST");
		else
			frame:UnregisterEvent("PARTY_INVITE_REQUEST");
		end

		-- Battleground release
		if LeaPlusOptionsLC["LeaPlusBGRelease"] == "On" then
			frame:RegisterEvent("PLAYER_DEAD");
		else
			frame:UnregisterEvent("PLAYER_DEAD");
		end

		-- Player chains
		if LeaPlusOptionsLC["LeaPlusPlayerGold"] == "On" then
			PlayerFrameTexture:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-Elite.blp");
		else
			PlayerFrameTexture:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame.blp");
		end

		-- Zone text
		if LeaPlusOptionsLC["LeaPlusZoneText"] == "On" then
			ZoneTextFrame:SetScript("OnShow", function() ZoneTextFrame:Hide() end)
		else
			ZoneTextFrame:SetScript("OnShow", function() ZoneTextFrame:Show() end)
		end

		-- Subzone text
		if LeaPlusOptionsLC["LeaPlusSubzoneText"] == "On" then
			SubZoneTextFrame:SetScript("OnShow", function() SubZoneTextFrame:Hide() end)
		else
			SubZoneTextFrame:SetScript("OnShow", function() SubZoneTextFrame:Show() end)
		end

		-- Classic chat
		if LeaPlusOptionsLC["LeaPlusOldChat"] == "On" then
			ChatTypeInfo['WHISPER']['sticky'] = 0
			ChatTypeInfo['BN_WHISPER']['sticky'] = 0
		else
			ChatTypeInfo['WHISPER']['sticky'] = 1
			ChatTypeInfo['BN_WHISPER']['sticky'] = 1
		end

		-- Dungeon Finder buttons
		if LeaPlusOptionsLC["LeaPlusLFGTimer"] == "On" then
			LeaPlusTimer:Show();
			LeaPlusHideRC:Show();
			if LFDRoleCheckPopup:IsShown() then
				LFDRoleCheckPopup:Hide();
			end
			LFDRoleCheckPopup:SetScript("OnShow", function()
				if LeaPlusHideRC:GetChecked() then 
					DEFAULT_CHAT_FRAME:AddMessage("Leatrix Plus blocked a dungeon role confirmation.", 1.0,0.85,0.0)
					LFDRoleCheckPopup:Hide();
				end
			end)
		else
			LeaPlusTimer:Hide();
			LeaPlusHideRC:Hide();
			LFDRoleCheckPopup:SetScript("OnShow", nil)
		end

		-- Character sheet buttons
		if LeaPlusOptionsLC["LeaPlusPlayerCharTog"] == "On" then
			LeaPlusCharHelm:Show();
			LeaPlusCharCloak:Show();
		else
			LeaPlusCharHelm:Hide();
			LeaPlusCharCloak:Hide();
		end

		-- World map boss buttons
		if LeaPlusOptionsLC["LeaPlusBossBtn"] == "On" then
			LeaPlusMapBoss:Show();
		else
			LeaPlusMapBoss:Hide();
		end

		-- Allow low level raids
		if LeaPlusOptionsLC["LeaPlusRaidCheck"] == "On" then
			SetAllowLowLevelRaid(1);
		else
			SetAllowLowLevelRaid(0);
		end

		-- Sell junk and repair options
		if LeaPlusOptionsLC["LeaPlusSellJunk"] == "On" or LeaPlusOptionsLC["LeaPlusRepairSelf"] == "On" then
			frame:RegisterEvent("MERCHANT_SHOW");
		else
			frame:UnregisterEvent("MERCHANT_SHOW");			
		end

		-- Get quests automatically
		if LeaPlusOptionsLC["LeaPlusQAccHead"] == "On" then
			frame:RegisterEvent("QUEST_DETAIL");
			frame:RegisterEvent("QUEST_ACCEPT_CONFIRM")
		else
			frame:UnregisterEvent("QUEST_DETAIL");			
			frame:UnregisterEvent("QUEST_ACCEPT_CONFIRM");			
		end

		-- Turn-in quests automatically
		if LeaPlusOptionsLC["LeaPlusQuestComplete"] == "On" then
			frame:RegisterEvent("QUEST_PROGRESS")
			frame:RegisterEvent("QUEST_COMPLETE")
		else
			frame:UnregisterEvent("QUEST_PROGRESS");			
			frame:UnregisterEvent("QUEST_COMPLETE");			
		end

		-- Enable arrow keys in chat
		if LeaPlusOptionsLC["LeaPlusChatArrow"] == "On" then
			for i = 1, NUM_CHAT_WINDOWS do
				local eb =  _G[format("%s%d%s", "ChatFrame", i, "EditBox")]
				_G[format("%s%d%s", "ChatFrame", i, "EditBox")]:SetAltArrowKeyMode(false)
			end
		else
			for i = 1, NUM_CHAT_WINDOWS do
				_G[format("%s%d%s", "ChatFrame", i, "EditBox")]:SetAltArrowKeyMode(true)
			end
		end

		-- Disable chat fade
		if LeaPlusOptionsLC["LeaPlusChatFade"] == "On" then
			for i = 1, NUM_CHAT_WINDOWS do
				_G[('ChatFrame'..i)]:SetFading(false)
			end
		else
			for i = 1, NUM_CHAT_WINDOWS do
				_G[('ChatFrame'..i)]:SetFading(true)
			end
		end

	LeaPlusQuestSizeUpdate();

	end

----------------------------------------------------------------------
-- 	Default Events
----------------------------------------------------------------------

	local function eventHandler(frame, event, arg1, arg2, ...)

		-- Block duels
		if event == "DUEL_REQUESTED" and not LeaPlusFriendCheck(arg1) then
			CancelDuel();
			StaticPopup_Hide("DUEL_REQUESTED");
		end

		-- Block guild pettitions
		if event == "PETITION_SHOW" and not LeaPlusFriendCheck(arg1) then
			ClosePetition();
		end

		-- Automatic resurrection
		if event == "RESURRECT_REQUEST" then
			AcceptResurrect();
			StaticPopup_Hide("RESURRECT_NO_TIMER");
		end

		-- Check for talent switch function
		if event == "ACTIVE_TALENT_GROUP_CHANGED" then
			DEFAULT_CHAT_FRAME:AddMessage("Talent spec changed.", 1.0,0.85,0.0)
		end

		-- Block party invites
		if event == "PARTY_INVITE_REQUEST" and not LeaPlusFriendCheck(arg1) then
			DeclineGroup(); 
			StaticPopup_Hide("PARTY_INVITE");
		end

		-- Don't confirm loot rolls
		if event == "CONFIRM_LOOT_ROLL" or event == "CONFIRM_DISENCHANT_ROLL" then
			if not IsShiftKeyDown() then
				ConfirmLootRoll(arg1, arg2)
				StaticPopup_Hide("CONFIRM_LOOT_ROLL")
			end
		end

		if event == "LOOT_BIND_CONFIRM" then
			if not IsShiftKeyDown() then
				ConfirmLootSlot(arg1, arg2);
				StaticPopup_Hide("LOOT_BIND",...)
			end
		end

		-- Sell junk automatically
		if event == "MERCHANT_SHOW" and LeaPlusOptionsLC["LeaPlusSellJunk"] == "On" then

			local LeaPlusTotal = 0
			local LeaPlusSoldCount = 0
			local LeaPlusRarity = 0
			local LeaPlusItemPrice = 0
			local LeaPlusItemCount = 0
			local CurrentItemLink

			for LeaPlusBagID = 0,4 do
				for LeaPlusBagSlot = 1, GetContainerNumSlots(LeaPlusBagID) do
					CurrentItemLink = GetContainerItemLink(LeaPlusBagID, LeaPlusBagSlot)
					if CurrentItemLink then
						_, _, LeaPlusRarity, _, _, _, _, _, _, _, LeaPlusItemPrice = GetItemInfo(CurrentItemLink)
						_, LeaPlusItemCount = GetContainerItemInfo(LeaPlusBagID, LeaPlusBagSlot)
						if LeaPlusRarity == 0 and LeaPlusItemPrice ~= 0 then
							LeaPlusTotal = LeaPlusTotal + (LeaPlusItemPrice * LeaPlusItemCount)
							LeaPlusSoldCount = LeaPlusSoldCount + 1
							UseContainerItem(LeaPlusBagID, LeaPlusBagSlot)
						end
					end
				end
			end
			if LeaPlusTotal ~= 0 then
				DEFAULT_CHAT_FRAME:AddMessage("Sold " .. LeaPlusSoldCount .. " grey items for " .. GetCoinTextureString(LeaPlusTotal) .. ".", r,g,b)
			end
		end

		-- Automatically accept quests
		if LeaPlusOptionsLC["LeaPlusQAccHead"] == "On" then

			if ((LeaPlusOptionsLC["LeaPlusQAccAll"] == "On") or (LeaPlusOptionsLC["LeaPlusQAccDaily"] == "On" and QuestIsDaily() == 1)) then

				-- Automatically accept all quests or daily quests with daily check on
				if event == "QUEST_DETAIL" then
					if not IsShiftKeyDown() then
						if not QuestGetAutoAccept() then
							-- If quest requires an accept click
							AcceptQuest()
						else
							-- If it's automatically accepted, just close the window
							CloseQuest()
						end
					end
				end

				-- Quests requiring confirmation
				if event == "QUEST_ACCEPT_CONFIRM" then
					if not IsShiftKeyDown() then
						ConfirmAcceptQuest()
						StaticPopup_Hide("QUEST_ACCEPT_CONFIRM")
					end
				end
			end
		end

		-- Automatically turn-in quests
		if LeaPlusOptionsLC["LeaPlusQuestComplete"] == "On" then

			-- Active quest turn-ins
			if event == "QUEST_PROGRESS" then
				if not IsShiftKeyDown() then
					if IsQuestCompletable() then
						CompleteQuest()
					end
				end
			end

			-- Turn-in completed quest
			if event == "QUEST_COMPLETE" then
				if not IsShiftKeyDown() then
					if GetNumQuestChoices() <= 1 then
						-- If there is only one reward item offered, grab it
						GetQuestReward(GetNumQuestChoices())
					end
				end
			end

		end

		-- Battleground release
		if event == "PLAYER_DEAD" then
			local InstStat, InstType = IsInInstance();
			if InstStat == 1 and InstType == "pvp" then
				-- Check for soulstone
				if not (LeaPlusSoulstone) then
					RepopMe();
				end
			end
		end

		-- Repair automatically
		if event == "MERCHANT_SHOW" and LeaPlusOptionsLC["LeaPlusRepairSelf"] == "On" then

			local function LeaPlusPlayerRepairFunc(LeaPlusRepairCost,LeaPlusPlayerMoney)
				if (LeaPlusRepairCost <= LeaPlusPlayerMoney) then -- if player has enough money
					RepairAllItems()
					DEFAULT_CHAT_FRAME:AddMessage("Repaired for " .. GetCoinTextureString(LeaPlusRepairCost) .. " (own funds).",r,g,b)
				else
					DEFAULT_CHAT_FRAME:AddMessage("The repair cost is " .. GetCoinTextureString(LeaPlusRepairCost) ..".",r,g,b)
					DEFAULT_CHAT_FRAME:AddMessage("You do not have enough money to automatically repair.",r,g,b)
				end
			end

			if CanMerchantRepair() then
				local LeaPlusPlayerMoney = GetMoney()
				local LeaPlusRepairCost, LeaPlusCanRepair = GetRepairAllCost()
				local LeaPlusRepType = 0

				if (LeaPlusCanRepair) then -- if the repair option is available at the merchant
					if LeaPlusPlayerMoney == nil then LeaPlusPlayerMoney = 0 end

					-- Guild bank repair
					if LeaPlusOptionsLC["LeaPlusRepairGuild"] == "On" and IsInGuild() then
						if CanGuildBankRepair() then -- if player can use guild bank for repair
							if LeaPlusRepairCost <= GetGuildBankMoney() then
								RepairAllItems(1)
								DEFAULT_CHAT_FRAME:AddMessage("Repaired for " .. GetCoinTextureString(LeaPlusRepairCost) .. " (guild).",r,g,b)
							else
								if LeaPlusOptionsLC["LeaPlusRepairForce"] == "On" then
									LeaPlusPlayerRepairFunc(LeaPlusRepairCost,LeaPlusPlayerMoney)
								else
									DEFAULT_CHAT_FRAME:AddMessage("The repair cost is " .. GetCoinTextureString(LeaPlusRepairCost) .. ".",r,g,b)
									DEFAULT_CHAT_FRAME:AddMessage("The guild bank doesn't have enough money to repair your items.",r,g,b)
								end
							end
						else
							if LeaPlusOptionsLC["LeaPlusRepairForce"] == "On" then
								LeaPlusPlayerRepairFunc(LeaPlusRepairCost,LeaPlusPlayerMoney)
							else
								DEFAULT_CHAT_FRAME:AddMessage("You do not have permission to repair using the guild bank.",r,g,b)
							end
						end

					-- Player repair
					else
						LeaPlusPlayerRepairFunc(LeaPlusRepairCost,LeaPlusPlayerMoney)
					end
				end
			end
		end

		-- Load saved variables or set to default if none exist
		if (event == "ADDON_LOADED" and arg1 == "Leatrix_Plus") then

			-- Copy globals to locals
			if LeaPlusOptionsDB["LeaPlusDeathEffect"] 		== nil then LeaPlusOptionsLC["LeaPlusDeathEffect"] 		= "On"	else LeaPlusOptionsLC["LeaPlusDeathEffect"] 	= LeaPlusOptionsDB["LeaPlusDeathEffect"] 	end 
			if LeaPlusOptionsDB["LeaPlusDeclineDuel"] 		== nil then LeaPlusOptionsLC["LeaPlusDeclineDuel"] 		= "On" 	else LeaPlusOptionsLC["LeaPlusDeclineDuel"] 	= LeaPlusOptionsDB["LeaPlusDeclineDuel"] 	end 
			if LeaPlusOptionsDB["LeaPlusClosePetition"] 	== nil then LeaPlusOptionsLC["LeaPlusClosePetition"] 	= "On"  else LeaPlusOptionsLC["LeaPlusClosePetition"]	= LeaPlusOptionsDB["LeaPlusClosePetition"] 	end 
			if LeaPlusOptionsDB["LeaPlusDeclineParty"] 		== nil then LeaPlusOptionsLC["LeaPlusDeclineParty"] 	= "Off" else LeaPlusOptionsLC["LeaPlusDeclineParty"] 	= LeaPlusOptionsDB["LeaPlusDeclineParty"] 	end 
			if LeaPlusOptionsDB["LeaPlusNormalRes"] 		== nil then LeaPlusOptionsLC["LeaPlusNormalRes"] 		= "Off"	else LeaPlusOptionsLC["LeaPlusNormalRes"] 		= LeaPlusOptionsDB["LeaPlusNormalRes"] 		end 
			if LeaPlusOptionsDB["LeaPlusDuelMessage"] 		== nil then LeaPlusOptionsLC["LeaPlusDuelMessage"] 		= "On"	else LeaPlusOptionsLC["LeaPlusDuelMessage"] 	= LeaPlusOptionsDB["LeaPlusDuelMessage"] 	end 
			if LeaPlusOptionsDB["LeaPlusDualSpec"] 			== nil then LeaPlusOptionsLC["LeaPlusDualSpec"] 		= "On"	else LeaPlusOptionsLC["LeaPlusDualSpec"] 		= LeaPlusOptionsDB["LeaPlusDualSpec"] 		end 
			if LeaPlusOptionsDB["LeaPlusDisBP"] 			== nil then LeaPlusOptionsLC["LeaPlusDisBP"] 			= "On"	else LeaPlusOptionsLC["LeaPlusDisBP"] 			= LeaPlusOptionsDB["LeaPlusDisBP"] 			end 
			if LeaPlusOptionsDB["LeaPlusPlayerGold"] 		== nil then LeaPlusOptionsLC["LeaPlusPlayerGold"] 		= "On"	else LeaPlusOptionsLC["LeaPlusPlayerGold"] 		= LeaPlusOptionsDB["LeaPlusPlayerGold"] 	end 
			if LeaPlusOptionsDB["LeaPlusGlowEffect"] 		== nil then LeaPlusOptionsLC["LeaPlusGlowEffect"] 		= "Off"	else LeaPlusOptionsLC["LeaPlusGlowEffect"] 		= LeaPlusOptionsDB["LeaPlusGlowEffect"] 	end 
			if LeaPlusOptionsDB["LeaPlusNetherEffect"] 		== nil then LeaPlusOptionsLC["LeaPlusNetherEffect"] 	= "On"	else LeaPlusOptionsLC["LeaPlusNetherEffect"] 	= LeaPlusOptionsDB["LeaPlusNetherEffect"] 	end 
			if LeaPlusOptionsDB["LeaPlusZoneText"] 			== nil then LeaPlusOptionsLC["LeaPlusZoneText"] 		= "On"	else LeaPlusOptionsLC["LeaPlusZoneText"] 		= LeaPlusOptionsDB["LeaPlusZoneText"] 		end 
			if LeaPlusOptionsDB["LeaPlusSubzoneText"] 		== nil then LeaPlusOptionsLC["LeaPlusSubzoneText"] 		= "On"	else LeaPlusOptionsLC["LeaPlusSubzoneText"] 	= LeaPlusOptionsDB["LeaPlusSubzoneText"] 	end 
			if LeaPlusOptionsDB["LeaPlusErrorMsg"] 			== nil then LeaPlusOptionsLC["LeaPlusErrorMsg"] 		= "On"	else LeaPlusOptionsLC["LeaPlusErrorMsg"] 		= LeaPlusOptionsDB["LeaPlusErrorMsg"] 		end 
			if LeaPlusOptionsDB["LeaPlusInfoMsg"] 			== nil then LeaPlusOptionsLC["LeaPlusInfoMsg"] 			= "Off"	else LeaPlusOptionsLC["LeaPlusInfoMsg"] 		= LeaPlusOptionsDB["LeaPlusInfoMsg"] 		end 
			if LeaPlusOptionsDB["LeaPlusQuestFont"] 		== nil then LeaPlusOptionsLC["LeaPlusQuestFont"] 		= "Off"	else LeaPlusOptionsLC["LeaPlusQuestFont"] 		= LeaPlusOptionsDB["LeaPlusQuestFont"] 		end 
			if LeaPlusOptionsDB["LeaPlusQuestSize"] 		== nil then LeaPlusOptionsLC["LeaPlusQuestSize"] 		= "18"	else LeaPlusOptionsLC["LeaPlusQuestSize"] 		= LeaPlusOptionsDB["LeaPlusQuestSize"] 		end 
			if LeaPlusOptionsDB["LeaPlusOldChat"] 			== nil then LeaPlusOptionsLC["LeaPlusOldChat"]	 		= "On"	else LeaPlusOptionsLC["LeaPlusOldChat"] 		= LeaPlusOptionsDB["LeaPlusOldChat"] 		end 
			if LeaPlusOptionsDB["LeaPlusBGRelease"] 		== nil then LeaPlusOptionsLC["LeaPlusBGRelease"]	 	= "On"	else LeaPlusOptionsLC["LeaPlusBGRelease"] 		= LeaPlusOptionsDB["LeaPlusBGRelease"] 		end 
			if LeaPlusOptionsDB["LeaPlusLFGTimer"] 			== nil then LeaPlusOptionsLC["LeaPlusLFGTimer"]	 		= "On"	else LeaPlusOptionsLC["LeaPlusLFGTimer"] 		= LeaPlusOptionsDB["LeaPlusLFGTimer"] 		end 
			if LeaPlusOptionsDB["LeaPlusSellJunk"] 			== nil then LeaPlusOptionsLC["LeaPlusSellJunk"]	 		= "Off"	else LeaPlusOptionsLC["LeaPlusSellJunk"] 		= LeaPlusOptionsDB["LeaPlusSellJunk"] 		end 
			if LeaPlusOptionsDB["LeaPlusRepairSelf"] 		== nil then LeaPlusOptionsLC["LeaPlusRepairSelf"]		= "Off"	else LeaPlusOptionsLC["LeaPlusRepairSelf"] 		= LeaPlusOptionsDB["LeaPlusRepairSelf"] 	end 
			if LeaPlusOptionsDB["LeaPlusRepairGuild"] 		== nil then LeaPlusOptionsLC["LeaPlusRepairGuild"]		= "Off"	else LeaPlusOptionsLC["LeaPlusRepairGuild"] 	= LeaPlusOptionsDB["LeaPlusRepairGuild"] 	end 
			if LeaPlusOptionsDB["LeaPlusRepairForce"] 		== nil then LeaPlusOptionsLC["LeaPlusRepairForce"]		= "Off"	else LeaPlusOptionsLC["LeaPlusRepairForce"] 	= LeaPlusOptionsDB["LeaPlusRepairForce"] 	end 
			if LeaPlusOptionsDB["LeaPlusQuestLevel"] 		== nil then LeaPlusOptionsLC["LeaPlusQuestLevel"]		= "On"	else LeaPlusOptionsLC["LeaPlusQuestLevel"] 		= LeaPlusOptionsDB["LeaPlusQuestLevel"] 	end 
			if LeaPlusOptionsDB["LeaPlusQAccHead"] 			== nil then LeaPlusOptionsLC["LeaPlusQAccHead"]			= "Off"	else LeaPlusOptionsLC["LeaPlusQAccHead"] 		= LeaPlusOptionsDB["LeaPlusQAccHead"] 		end 
			if LeaPlusOptionsDB["LeaPlusQAccAll"] 			== nil then LeaPlusOptionsLC["LeaPlusQAccAll"]			= "Off"	else LeaPlusOptionsLC["LeaPlusQAccAll"] 		= LeaPlusOptionsDB["LeaPlusQAccAll"] 		end 
			if LeaPlusOptionsDB["LeaPlusQAccDaily"] 		== nil then LeaPlusOptionsLC["LeaPlusQAccDaily"]		= "Off"	else LeaPlusOptionsLC["LeaPlusQAccDaily"] 		= LeaPlusOptionsDB["LeaPlusQAccDaily"] 		end 
			if LeaPlusOptionsDB["LeaPlusQuestComplete"] 	== nil then LeaPlusOptionsLC["LeaPlusQuestComplete"]	= "Off"	else LeaPlusOptionsLC["LeaPlusQuestComplete"] 	= LeaPlusOptionsDB["LeaPlusQuestComplete"] 	end 
			if LeaPlusOptionsDB["LeaPlusLootNoConfirm"] 	== nil then LeaPlusOptionsLC["LeaPlusLootNoConfirm"]	= "Off"	else LeaPlusOptionsLC["LeaPlusLootNoConfirm"] 	= LeaPlusOptionsDB["LeaPlusLootNoConfirm"] 	end 
			if LeaPlusOptionsDB["LeaPlusSpecialEffect"] 	== nil then LeaPlusOptionsLC["LeaPlusSpecialEffect"]	= "Off"	else LeaPlusOptionsLC["LeaPlusSpecialEffect"] 	= LeaPlusOptionsDB["LeaPlusSpecialEffect"] 	end 
			if LeaPlusOptionsDB["LeaPlusRaidCheck"] 		== nil then LeaPlusOptionsLC["LeaPlusRaidCheck"]		= "On"	else LeaPlusOptionsLC["LeaPlusRaidCheck"] 		= LeaPlusOptionsDB["LeaPlusRaidCheck"] 		end 
			if LeaPlusOptionsDB["LeaPlusInterruptMsg"]	 	== nil then LeaPlusOptionsLC["LeaPlusInterruptMsg"]		= "Off"	else LeaPlusOptionsLC["LeaPlusInterruptMsg"]	= LeaPlusOptionsDB["LeaPlusInterruptMsg"]	end 
			if LeaPlusOptionsDB["LeaPlusChatArrow"]	 		== nil then LeaPlusOptionsLC["LeaPlusChatArrow"]		= "On"	else LeaPlusOptionsLC["LeaPlusChatArrow"]		= LeaPlusOptionsDB["LeaPlusChatArrow"]		end 
			if LeaPlusOptionsDB["LeaPlusChatFade"]	 		== nil then LeaPlusOptionsLC["LeaPlusChatFade"]			= "Off"	else LeaPlusOptionsLC["LeaPlusChatFade"]		= LeaPlusOptionsDB["LeaPlusChatFade"]		end 
			if LeaPlusOptionsDB["LeaPlusGryphons"]	 		== nil then LeaPlusOptionsLC["LeaPlusGryphons"]			= "Off"	else LeaPlusOptionsLC["LeaPlusGryphons"]		= LeaPlusOptionsDB["LeaPlusGryphons"]		end 
			if LeaPlusOptionsDB["LeaPlusZoomOut"]	 		== nil then LeaPlusOptionsLC["LeaPlusZoomOut"]			= "Off"	else LeaPlusOptionsLC["LeaPlusZoomOut"]			= LeaPlusOptionsDB["LeaPlusZoomOut"]		end 
			if LeaPlusOptionsDB["LeaPlusPlayerCharTog"]		== nil then LeaPlusOptionsLC["LeaPlusPlayerCharTog"]	= "On"	else LeaPlusOptionsLC["LeaPlusPlayerCharTog"]	= LeaPlusOptionsDB["LeaPlusPlayerCharTog"]	end 
			if LeaPlusOptionsDB["LeaPlusBossBtn"]			== nil then LeaPlusOptionsLC["LeaPlusBossBtn"]			= "On"	else LeaPlusOptionsLC["LeaPlusBossBtn"]			= LeaPlusOptionsDB["LeaPlusBossBtn"]		end 
			if LeaPlusOptionsDB["LeaPlusPetIcon"]			== nil then LeaPlusOptionsLC["LeaPlusPetIcon"]			= "Off"	else LeaPlusOptionsLC["LeaPlusPetIcon"]			= LeaPlusOptionsDB["LeaPlusPetIcon"]		end 
			if LeaPlusOptionsDB["LeaPlusShowHks"]			== nil then LeaPlusOptionsLC["LeaPlusShowHks"]			= "On"	else LeaPlusOptionsLC["LeaPlusShowHks"]			= LeaPlusOptionsDB["LeaPlusShowHks"]		end 

			UIParentLoadAddOn("Blizzard_DebugTools")
			DEFAULT_CHAT_FRAME:AddMessage("Leatrix Plus loaded successfully.", 1.0,0.85,0.0)
			wipe(LeaPlusOptionsDB)
			if LeaPlusPlayerClass == "HUNTER" then
				LeaPlusShowMendPet();
			end
			LeaPlusShowHkFunc();
			DoItNow(frame);
		end

		if (event == "PLAYER_LOGIN") then
			LeaPlusSetDim();
		end

		-- Save locals back to globals on logout
		if (event == "PLAYER_LOGOUT") then

			-- Save locals to globals
			LeaPlusOptionsDB["LeaPlusDeathEffect"] 		= LeaPlusOptionsLC["LeaPlusDeathEffect"]
			LeaPlusOptionsDB["LeaPlusDeclineDuel"] 		= LeaPlusOptionsLC["LeaPlusDeclineDuel"]
			LeaPlusOptionsDB["LeaPlusClosePetition"]	= LeaPlusOptionsLC["LeaPlusClosePetition"]
			LeaPlusOptionsDB["LeaPlusDeclineParty"]	 	= LeaPlusOptionsLC["LeaPlusDeclineParty"]
			LeaPlusOptionsDB["LeaPlusNormalRes"] 		= LeaPlusOptionsLC["LeaPlusNormalRes"]
			LeaPlusOptionsDB["LeaPlusDuelMessage"] 		= LeaPlusOptionsLC["LeaPlusDuelMessage"]
			LeaPlusOptionsDB["LeaPlusDualSpec"] 		= LeaPlusOptionsLC["LeaPlusDualSpec"]
			LeaPlusOptionsDB["LeaPlusDisBP"] 			= LeaPlusOptionsLC["LeaPlusDisBP"]
			LeaPlusOptionsDB["LeaPlusPlayerGold"] 		= LeaPlusOptionsLC["LeaPlusPlayerGold"]
			LeaPlusOptionsDB["LeaPlusGlowEffect"] 		= LeaPlusOptionsLC["LeaPlusGlowEffect"]
			LeaPlusOptionsDB["LeaPlusNetherEffect"] 	= LeaPlusOptionsLC["LeaPlusNetherEffect"]
			LeaPlusOptionsDB["LeaPlusZoneText"] 		= LeaPlusOptionsLC["LeaPlusZoneText"]
			LeaPlusOptionsDB["LeaPlusSubzoneText"] 		= LeaPlusOptionsLC["LeaPlusSubzoneText"]
			LeaPlusOptionsDB["LeaPlusErrorMsg"] 		= LeaPlusOptionsLC["LeaPlusErrorMsg"]
			LeaPlusOptionsDB["LeaPlusInfoMsg"] 			= LeaPlusOptionsLC["LeaPlusInfoMsg"]
			LeaPlusOptionsDB["LeaPlusQuestFont"] 		= LeaPlusOptionsLC["LeaPlusQuestFont"]
			LeaPlusOptionsDB["LeaPlusQuestSize"] 		= LeaPlusOptionsLC["LeaPlusQuestSize"]
			LeaPlusOptionsDB["LeaPlusOldChat"] 			= LeaPlusOptionsLC["LeaPlusOldChat"]
			LeaPlusOptionsDB["LeaPlusBGRelease"] 		= LeaPlusOptionsLC["LeaPlusBGRelease"]
			LeaPlusOptionsDB["LeaPlusLFGTimer"] 		= LeaPlusOptionsLC["LeaPlusLFGTimer"]
			LeaPlusOptionsDB["LeaPlusSellJunk"] 		= LeaPlusOptionsLC["LeaPlusSellJunk"]
			LeaPlusOptionsDB["LeaPlusRepairSelf"] 		= LeaPlusOptionsLC["LeaPlusRepairSelf"]
			LeaPlusOptionsDB["LeaPlusRepairGuild"] 		= LeaPlusOptionsLC["LeaPlusRepairGuild"]
			LeaPlusOptionsDB["LeaPlusRepairForce"] 		= LeaPlusOptionsLC["LeaPlusRepairForce"]
			LeaPlusOptionsDB["LeaPlusQuestLevel"] 		= LeaPlusOptionsLC["LeaPlusQuestLevel"]
			LeaPlusOptionsDB["LeaPlusQAccHead"] 		= LeaPlusOptionsLC["LeaPlusQAccHead"]
			LeaPlusOptionsDB["LeaPlusQAccAll"] 			= LeaPlusOptionsLC["LeaPlusQAccAll"]
			LeaPlusOptionsDB["LeaPlusQAccDaily"] 		= LeaPlusOptionsLC["LeaPlusQAccDaily"]
			LeaPlusOptionsDB["LeaPlusQuestComplete"] 	= LeaPlusOptionsLC["LeaPlusQuestComplete"]
			LeaPlusOptionsDB["LeaPlusLootNoConfirm"] 	= LeaPlusOptionsLC["LeaPlusLootNoConfirm"]
			LeaPlusOptionsDB["LeaPlusSpecialEffect"] 	= LeaPlusOptionsLC["LeaPlusSpecialEffect"]
			LeaPlusOptionsDB["LeaPlusRaidCheck"]	 	= LeaPlusOptionsLC["LeaPlusRaidCheck"]
			LeaPlusOptionsDB["LeaPlusInterruptMsg"]	 	= LeaPlusOptionsLC["LeaPlusInterruptMsg"]
			LeaPlusOptionsDB["LeaPlusChatArrow"]	 	= LeaPlusOptionsLC["LeaPlusChatArrow"]
			LeaPlusOptionsDB["LeaPlusChatFade"]		 	= LeaPlusOptionsLC["LeaPlusChatFade"]
			LeaPlusOptionsDB["LeaPlusGryphons"]		 	= LeaPlusOptionsLC["LeaPlusGryphons"]
			LeaPlusOptionsDB["LeaPlusZoomOut"]		 	= LeaPlusOptionsLC["LeaPlusZoomOut"]
			LeaPlusOptionsDB["LeaPlusPlayerCharTog"] 	= LeaPlusOptionsLC["LeaPlusPlayerCharTog"]
			LeaPlusOptionsDB["LeaPlusBossBtn"] 			= LeaPlusOptionsLC["LeaPlusBossBtn"]
			LeaPlusOptionsDB["LeaPlusPetIcon"] 			= LeaPlusOptionsLC["LeaPlusPetIcon"]
			LeaPlusOptionsDB["LeaPlusShowHks"] 			= LeaPlusOptionsLC["LeaPlusShowHks"]
		end

	end

----------------------------------------------------------------------
--	Error events
----------------------------------------------------------------------

	local function ErrEventHandler(self, event, LeaPlusError, ...)

		-- Handle error messages
		if event == "UI_ERROR_MESSAGE" then
			if LeaPlusOptionsLC["LeaPlusErrorMsg"] == "On" then
				for k,v in pairs(LeaPlusErrArray) do
					if string.lower(LeaPlusError):find(v) then
						return Leatrix_Script(self, event, LeaPlusError, ...) 
					end
				end
			elseif LeaPlusOptionsLC["LeaPlusErrorMsg"] == "Off" then
				return Leatrix_Script(self, event, LeaPlusError, ...) 
			end
		end

		-- Handle system messages
		if event == 'SYSMSG' then
			if LeaPlusOptionsLC["LeaPlusInfoMsg"] == "On" then
				return
			else
				return Leatrix_Script(self, event, LeaPlusError, ...)
			end
		end

		-- Handle information messages
		if event == 'UI_INFO_MESSAGE' then
			if LeaPlusOptionsLC["LeaPlusInfoMsg"] == "On" then
				return
			else
				return Leatrix_Script(self, event, LeaPlusError, ...)
			end
		end

	end

--	Register event handler
	frame:SetScript("OnEvent", eventHandler);
	UIErrorsFrame:SetScript('OnEvent', ErrEventHandler)

----------------------------------------------------------------------
-- Slash commands
----------------------------------------------------------------------

--	Slash command handler
	local function slashCommand(str)
		if str == '' then
			InterfaceOptionsFrame_OpenToCategory(LeaPlusOptChar);
		elseif str == 'help' then DEFAULT_CHAT_FRAME:AddMessage("Leatrix Plus\n/ltp - Show options panel\n/ltp toggle - Toggle hiding errors\n/ltp frame - Toggle frame Information\n/ltp reload - Reload the UI\n/ltp restart - Restart the graphics engine", r,g,b)
		elseif str == "frame" then
			FrameStackTooltip_Toggle();
		elseif str == "reload" then
			ReloadUI();
		elseif str == "restart" then
			RestartGx();
		elseif str == "toggle" then
			if LeaPlusOptionsLC["LeaPlusErrorMsg"] == "Off" then
				LeaPlusOptionsLC["LeaPlusErrorMsg"] = "On"
				DEFAULT_CHAT_FRAME:AddMessage("Error messages will now be hidden.",  r,g,b)
			elseif LeaPlusOptionsLC["LeaPlusErrorMsg"] == "On" then
				LeaPlusOptionsLC["LeaPlusErrorMsg"] = "Off"
				DEFAULT_CHAT_FRAME:AddMessage("Error messages will now be shown.",  r,g,b)
			end
		else
			DEFAULT_CHAT_FRAME:AddMessage("Invalid command.  Type '/ltp help' for help.",  r,g,b)
		end
	end

--	Slash command support
	SLASH_Leatrix_Plus1 = '/ltp'
	SLASH_Leatrix_Plus2 = '/leaplus'
	SlashCmdList["Leatrix_Plus"] = function(str) slashCommand(string.lower(str)) end
	
----------------------------------------------------------------------
-- 	Options panel functions
----------------------------------------------------------------------

	-- Define panel title
	local function OptionsTitle(title,subtitle,LeaOptionsFrame)
		local text = LeaOptionsFrame:CreateFontString(nil, 'ARTWORK', 'GameFontNormalLarge')
		text:SetPoint('TOPLEFT', 16, -16)
		text:SetText(title)
			local subtext = LeaOptionsFrame:CreateFontString(nil, 'ARTWORK', 'GameFontHighlightSmall')
		subtext:SetHeight(32)
		subtext:SetPoint('TOPLEFT', text, 'BOTTOMLEFT', 0, -8)
		subtext:SetPoint('RIGHT', LeaOptionsFrame, -32, 0)
		subtext:SetNonSpaceWrap(true)
		subtext:SetJustifyH('LEFT')
		subtext:SetJustifyV('TOP')
		subtext:SetText(subtitle)
	end
	
	-- Define subheadings
	local function OptionsText(title,x,y,LeaOptionsFrame)
		local text = LeaOptionsFrame:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
		text:SetPoint("TOPLEFT",x,y)
		text:SetText(title)
	end

	-- Define text
	local function OptionsWords(title,x,y,LeaOptionsFrame)
		local text = LeaOptionsFrame:CreateFontString(nil, 'ARTWORK', 'GameFontHighlight')
		text:SetPoint("TOPLEFT",x,y)
		text:SetText(title)
	end

	-- Define slider control
	local function LeaSlider(LeaPlusSliderName,field,caption,low, high, step, x,y, form, LeaPlusSliderLText, LeaPlusSliderRText,LeaOptionsFrame)
		local function slider_OnMouseWheel(LeaOptionsFrame, arg1)
			local step = LeaOptionsFrame:GetValueStep() * arg1
			local value = LeaOptionsFrame:GetValue()
			local minVal, maxVal = LeaOptionsFrame:GetMinMaxValues()
			if step > 0 then
				LeaOptionsFrame:SetValue(min(value+step, maxVal))
			else
				LeaOptionsFrame:SetValue(max(value+step, minVal))
			end
		end

		local LeaPlusSliderName = CreateFrame('slider', field, LeaOptionsFrame, 'OptionssliderTemplate')
		getglobal(LeaPlusSliderName:GetName() .. 'Text'):SetText(caption)

		LeaPlusSliderName:SetScript('OnShow', function(LeaOptionsFrame)
			LeaOptionsFrame.onShow = true
			LeaOptionsFrame:SetValue(LeaPlusOptionsLC[field])
			LeaOptionsFrame.onShow = nil
		end)

		-- Change the value when you drag the slider
		LeaPlusSliderName:SetScript('OnValueChanged', function(LeaOptionsFrame, value)
			LeaOptionsFrame.valText:SetText(format(form, value))
			LeaPlusOptionsLC[field] = value
			LeaPlusQuestSizeUpdate();
		end)

		-- Setup slider layout
		LeaPlusSliderName:SetMinMaxValues(low, high)
		LeaPlusSliderName:SetValueStep(step)
		LeaPlusSliderName:EnableMouseWheel(true)
		LeaPlusSliderName:SetScript('OnMouseWheel', slider_OnMouseWheel)
		LeaPlusSliderName:SetPoint('TOPLEFT', x,y)
		LeaPlusSliderName.tooltipText = "Drag the slider."
		getglobal(LeaPlusSliderName:GetName() .. 'Low'):SetText(LeaPlusSliderLText);
		getglobal(LeaPlusSliderName:GetName() .. 'High'):SetText(LeaPlusSliderRText);
		LeaPlusSliderName:SetWidth(100)
		LeaPlusSliderName:SetHeight(20)

		-- Show text value next to the slider
		local text = LeaPlusSliderName:CreateFontString(nil, 'BACKGROUND')
		text:SetFontObject('GameFontHighlight')
		text:SetPoint('LEFT', LeaPlusSliderName, 'RIGHT', 12, 0)
		LeaPlusSliderName.valText = text
		text:SetText(string.format("%.2f", LeaPlusSliderName:GetValue()))
	end

	-- Define Checkbox control
	local function LeaPlusCheckbox(field,caption,x,y,tip,LeaOptionsFrame,LeaOptionsCheckTemp)
		if LeaOptionsCheckTemp then
			LeaOptionsCheckTemp = "OptionsCheckButtonTemplate"
		else
			LeaOptionsCheckTemp = "ChatConfigCheckButtonTemplate"
		end
		local checkbox = CreateFrame('CheckButton', field, LeaOptionsFrame, LeaOptionsCheckTemp)
		getglobal(checkbox:GetName() .. 'Text'):SetText(caption)
		
		checkbox:SetScript('OnShow', function(LeaOptionsFrame) LeaOptionsFrame:SetChecked(LeaPlusOptionsLC[field]) end)
		checkbox:SetScript('OnClick', function(LeaOptionsFrame)
			if field == "LeaPlusCharHelm" then
				if LeaPlusCharHelm:GetChecked() then 
					ShowHelm(1)
				else
					ShowHelm(0)
				end
				return
			end
			if field == "LeaPlusCharCloak" then
				if LeaPlusCharCloak:GetChecked() then 
					ShowCloak(1)
				else
					ShowCloak(0)
				end
				return
			end
			if checkbox:GetChecked() == nil then
				LeaPlusOptionsLC[field] = "Off"
			elseif checkbox:GetChecked() == 1 then
				LeaPlusOptionsLC[field] = "On"
			end
			if field == "LeaPlusQuestLevel" then
				if QuestLogFrame:IsShown() then
					QuestLogFrame:Hide()
					QuestLogFrame:Show()
				end
			end
			if field == "LeaPlusShowHks" then
				if PVPFrame:IsShown() then
					PVPFrame:Hide()
					PVPFrame:Show()
				end
			end
			LeaPlusSetDim();
			DoItNow(frame);
			if field == "LeaPlusPlayerCharTog" then
				if LeaPlusOptionsLC["LeaPlusPlayerCharTog"] == "On" then
					if ShowingHelm() then
						LeaPlusCharHelm:SetChecked(true)
					else
						LeaPlusCharHelm:SetChecked(false)
					end
					if ShowingCloak() then
						LeaPlusCharCloak:SetChecked(true)
					else
						LeaPlusCharCloak:SetChecked(false)
					end
				end
			end
			if field == "LeaPlusMapBoss" then
				-- Hide boss buttons on the map
				if LeaPlusOptionsLC["LeaPlusBossBtn"] == "On" then
					if WorldMapBossButtonFrame:IsShown() then
						WorldMapBossButtonFrame:Hide()
					else
						WorldMapBossButtonFrame:Show()
					end
				end
			end
		end)
		checkbox:SetPoint("TOPLEFT",x, y)
		checkbox.tooltip = tip;
	end

	-- Define button
	local function LeaPlusButton(name,frm,label,anchor,x,y,width,height,tip)
		local LeaPlusDeflt = CreateFrame("Button", name, frm, "UIPanelButtonTemplate") 
		LeaPlusDeflt:SetWidth(width)
		LeaPlusDeflt:SetHeight(height) 
		LeaPlusDeflt:SetAlpha(1.0)
		LeaPlusDeflt:SetPoint(anchor, x, y)
		LeaPlusDeflt:SetText(label) 
		LeaPlusDeflt:RegisterForClicks("AnyUp") 
		LeaPlusDeflt.tiptext = tip
		LeaPlusDeflt:SetScript("OnEnter", ShowTooltip)		
		LeaPlusDeflt:SetScript("OnLeave", HideTooltip)
	end

----------------------------------------------------------------------
-- 	Options panel (title)
----------------------------------------------------------------------

-- 	Define the options panel (last line drop is 352)
	local LeaPlusOpt0 = CreateFrame('Frame', 'LeaPlusOpt0', UIParent)

	function LeaPlusOpt0:OptionsPanel()
		LeaPlusOpt0.name = "Leatrix Plus"
		OptionsTitle("Leatrix Plus",(select(3, GetAddOnInfo("Leatrix_Plus"))),LeaPlusOpt0);
		OptionsText("Welcome to Leatrix Plus.", 16, -72,LeaPlusOpt0);
		OptionsWords("To begin, choose an options page from the menu to the left.", 16, -92,LeaPlusOpt0);
		OptionsWords("You can launch page one directly using /ltp.", 16, -112,LeaPlusOpt0);

----------------------------------------------------------------------
-- 	Character & Vendors
----------------------------------------------------------------------

		local LeaPlusOptChar = CreateFrame('Frame', 'LeaPlusOptChar', LeaPlusOpt0)
	
		LeaPlusOptChar.name = "Character & Vendors"
		LeaPlusOptChar.parent = "Leatrix Plus"

		OptionsTitle("Leatrix Plus",(select(3, GetAddOnInfo("Leatrix_Plus"))),LeaPlusOptChar);

		OptionsText("Character", 16, -72,LeaPlusOptChar);
		LeaPlusCheckbox("LeaPlusNormalRes",		"Automated resurrect", 			16, -92, 	"If checked, resurrection attempts cast on you will be automatically accepted.",LeaPlusOptChar)
		LeaPlusCheckbox("LeaPlusPlayerCharTog",	"Show helm/cloak buttons", 		16, -112, 	"If checked, two buttons will be added to the character sheet to allow you to toggle your helm and cloak easily.\n\nThese checkboxes are not clickable while you are dead.",LeaPlusOptChar)
		LeaPlusCheckbox("LeaPlusPlayerGold", 	"Show elite chain",				16, -132, 	"If checked, your player portrait will have an elite gold chain around it.",LeaPlusOptChar)

		OptionsText("Blockers", 16, -172,LeaPlusOptChar);
		LeaPlusCheckbox("LeaPlusDeclineDuel", 	"Block duels",	 				16, -192, 	"If checked, duel requests will be blocked unless the player requesting the duel is in your friends list.",LeaPlusOptChar)
		LeaPlusCheckbox("LeaPlusClosePetition", "Block guild petitions",		16, -212, 	"If checked, guild petition signature requests will be blocked unless the player requesting the signature is in your friends list.",LeaPlusOptChar)
		LeaPlusCheckbox("LeaPlusDeclineParty", 	"Block party invites", 			16, -232, 	"If checked, party invitations will be blocked unless the player inviting you is in your friends list.",LeaPlusOptChar)

		OptionsText("Vendors", 280, -72,LeaPlusOptChar);
		LeaPlusCheckbox("LeaPlusSellJunk", 		"Sell junk automatically",		280, -92, 	"If checked, all grey items in your bags will be automatically sold when you visit a merchant.",LeaPlusOptChar)
		LeaPlusCheckbox("LeaPlusRepairSelf", 	"Automatically repair",			280, -112, 	"If checked, your armor will be automatically repaired when you visit a suitable merchant.",LeaPlusOptChar)
		LeaPlusCheckbox("LeaPlusRepairGuild", 	"Use guild funds",				300, -132, 	"If checked, guild funds will be used with the automatic repair option for your characters that are guilded.",LeaPlusOptChar)
		LeaPlusCheckbox("LeaPlusRepairForce", 	"Fallback on own money",		300, -152, 	"If checked, repair costs will be taken from your own money if you do not have permission to use the guild bank or the guild bank does not have enough money.",LeaPlusOptChar)
		LeaPlusCheckbox("LeaPlusDisBP", 		"Prevent bag automation",		280, -172, 	"If checked, bags will not be opened and closed automatically when using a vendor or mailbox, allowing you to open and close them freely at your command.",LeaPlusOptChar)

		LeaPlusButton("LeaPlusDefltChar",LeaPlusOptChar,"Set Defaults","BOTTOMLEFT",10,10,130,25,"Resets all the options on this page back to the default settings.")
		LeaPlusDefltChar:SetScript("OnClick", function() 
			LeaPlusOptionsLC["LeaPlusDeclineDuel"] 		= "On"
			LeaPlusOptionsLC["LeaPlusClosePetition"] 	= "On"
			LeaPlusOptionsLC["LeaPlusDeclineParty"] 	= "Off"
			LeaPlusOptionsLC["LeaPlusNormalRes"] 		= "Off"
			LeaPlusOptionsLC["LeaPlusPlayerCharTog"]	= "On"
			LeaPlusOptionsLC["LeaPlusPlayerGold"] 		= "On"
			LeaPlusOptionsLC["LeaPlusSellJunk"]			= "Off"
			LeaPlusOptionsLC["LeaPlusRepairSelf"]		= "Off"
			LeaPlusOptionsLC["LeaPlusRepairGuild"]		= "Off"
			LeaPlusOptionsLC["LeaPlusRepairForce"]		= "Off"
			LeaPlusOptionsLC["LeaPlusDisBP"] 			= "On"
			LeaPlusSetDim()
			LeaPlusOptChar:Hide();
			LeaPlusOptChar:Show();
			DoItNow(frame);
		end)

----------------------------------------------------------------------
-- 	Text & Chat
----------------------------------------------------------------------

		local LeaPlusOptText = CreateFrame('Frame', 'LeaPlusOptText', LeaPlusOpt0)
	
		LeaPlusOptText.name = "Text & Chat"
		LeaPlusOptText.parent = "Leatrix Plus"

		OptionsTitle("Leatrix Plus",(select(3, GetAddOnInfo("Leatrix_Plus"))),LeaPlusOptText);

		OptionsText("Chat", 16, -72,LeaPlusOptText);
		LeaPlusCheckbox("LeaPlusDuelMessage", 	"Hide duel messages", 			16, -92, 	"If checked, duel messages will be blocked unless you took part in the duel.",LeaPlusOptText)
		LeaPlusCheckbox("LeaPlusDualSpec", 		"Hide dual-spec spam", 			16, -112, 	"If checked, switching specs will not flood your chat window with dual-spec spam.",LeaPlusOptText)
		LeaPlusCheckbox("LeaPlusOldChat", 		"Use classic chat", 			16, -132, 	"If checked, you can press enter to talk in group chat using whatever method you used last (say, party, guild, etc).\n\nTo reply to whispers, press r as normal.",LeaPlusOptText)
		LeaPlusCheckbox("LeaPlusChatArrow", 	"Use arrow keys in chat", 		16, -152, 	"If checked, you can press the arrow keys to move your insertion point left and right in the chat frame.\n\nIf unchecked, the arrow keys will use the default keybind setting.",LeaPlusOptText)
		LeaPlusCheckbox("LeaPlusChatFade", 		"Disable chat fade", 			16, -172, 	"If checked, chat text will not fade out after a time period.",LeaPlusOptText)

		OptionsText("Zone Text", 280, -72,LeaPlusOptText);
		LeaPlusCheckbox("LeaPlusZoneText",	 	"Hide zone text",				280, -92, 	"If checked, zone text will not be shown (eg. 'Ironforge').",LeaPlusOptText)
		LeaPlusCheckbox("LeaPlusSubzoneText", 	"Hide subzone text",			280, -112, 	"If checked, subzone text will not be shown (eg. 'Mystic Quarter').",LeaPlusOptText)

		OptionsText("Errors", 280, -152,LeaPlusOptText);
		LeaPlusCheckbox("LeaPlusErrorMsg", 		"Hide error messages",		 	280, -172, 	"If checked, error messages (eg. 'Not enough rage') will not be shown in the error frame.\n\nErrors containing the following will always be shown regardless of this option:" .. LeaPlusErrTip .. "\n\nYou may wish to create a macro containing '/ltp toggle' which will toggle this option when clicked.",LeaPlusOptText)
		LeaPlusCheckbox("LeaPlusInfoMsg", 		"Hide info messages", 			280, -192, 	"If checked, information and system messages (eg. quest updates) will not be shown in the error frame.",LeaPlusOptText)

		LeaPlusButton("LeaPlusDefltText",LeaPlusOptText,"Set Defaults","BOTTOMLEFT",10,10,130,25,"Resets all the options on this page back to the default settings.")
		LeaPlusDefltText:SetScript("OnClick", function() 
			LeaPlusOptionsLC["LeaPlusDuelMessage"] 		= "On"
			LeaPlusOptionsLC["LeaPlusDualSpec"]			= "On"
			LeaPlusOptionsLC["LeaPlusOldChat"]			= "On"
			LeaPlusOptionsLC["LeaPlusChatArrow"]	 	= "On"
			LeaPlusOptionsLC["LeaPlusChatFade"]		 	= "Off"
			LeaPlusOptionsLC["LeaPlusZoneText"] 		= "On"
			LeaPlusOptionsLC["LeaPlusSubzoneText"]	 	= "On"
			LeaPlusOptionsLC["LeaPlusErrorMsg"]	 		= "On"
			LeaPlusOptionsLC["LeaPlusInfoMsg"]	 		= "Off"
			LeaPlusSetDim()
			LeaPlusOptText:Hide();
			LeaPlusOptText:Show();
			DoItNow(frame);
		end)

----------------------------------------------------------------------
-- 	Quests & Dungeons
----------------------------------------------------------------------

		local LeaPlusOptQuests = CreateFrame('Frame', 'LeaPlusOptQuests', LeaPlusOpt0)
	
		LeaPlusOptQuests.name = "Quests & Dungeons"
		LeaPlusOptQuests.parent = "Leatrix Plus"

		OptionsTitle("Leatrix Plus",(select(3, GetAddOnInfo("Leatrix_Plus"))),LeaPlusOptQuests);

		OptionsText("Quests", 16, -72,LeaPlusOptQuests);
		LeaPlusCheckbox("LeaPlusQuestLevel", 	"Show quest levels",			16, -92, 	"If checked, quest levels will be shown in the quest log.",LeaPlusOptQuests)
		LeaPlusCheckbox("LeaPlusQAccHead", 		"Accept quests automatically",	16, -112, 	"If checked, you can specify which quests you want to accept automatically.\n\nYou can hold the shift key down when you talk to a quest giver to over-ride this setting.",LeaPlusOptQuests)
		LeaPlusCheckbox("LeaPlusQAccAll", 		"All quests",					36, -132, 	"If checked, all quests will be accepted automatically.",LeaPlusOptQuests)
		LeaPlusCheckbox("LeaPlusQAccDaily", 	"Daily quests",					36, -152, 	"If checked, daily quests will be accepted automatically.",LeaPlusOptQuests)
		LeaPlusCheckbox("LeaPlusQuestComplete",	"Turn-in quests automatically",	16, -172, 	"If checked, quests will be turned-in automatically.\n\nYou can hold the shift key down when you talk to a quest giver to over-ride this setting.",LeaPlusOptQuests)

		OptionsText("Text Size", 16, -212,LeaPlusOptQuests);
		LeaPlusCheckbox("LeaPlusQuestFont", 	"Resize quest log text", 		16, -232, 	"If checked, quest log text will be resized according to the value set by the slider.  This will also affect a few other windows.",LeaPlusOptQuests)
		LeaSlider("LeaPlusScaleSlider","LeaPlusQuestSize","",10, 36, 1, 40, -262,"%.0f", "10", "36",LeaPlusOptQuests)

		OptionsText("Dungeons and Raids", 280, -72,LeaPlusOptQuests);
		LeaPlusCheckbox("LeaPlusLFGTimer", 		"Show dungeon buttons",			280, -92, 	"If checked, a time button will be shown in the Dungeon Finder frame which will toggle your random dungeon cooldown.\n\nA checkbox will also be available next to it which will prevent the 'Choose your role' window from showing if checked.",LeaPlusOptQuests)
		LeaPlusCheckbox("LeaPlusRaidCheck", 	"Allow low level raids",		280, -112, 	"If checked, your low level characters will be allowed to join raids.\n\nWhen combined with a free starter account, this option will allow you to create raid groups without requiring the help of another player.",LeaPlusOptQuests)
		LeaPlusCheckbox("LeaPlusLootNoConfirm", "Don't confirm loot rolls",		280, -132, 	"If checked, you will not be asked to confirm rolls on loot.\n\nThis includes need, greed, disenchant and soulbound confirmations.\n\nYou can hold the shift key down while looting to over-ride this option.",LeaPlusOptQuests)
		LeaPlusCheckbox("LeaPlusInterruptMsg", 	"Block interrupt messages", 	280, -152, 	"If checked, messages will be blocked in party chat and say chat if they contain any of the words below" .. LeaPlusSpamTip .. "\n\nThis only applies while you are inside an instance (of any type) and only while you are in combat.",LeaPlusOptQuests)
		LeaPlusCheckbox("LeaPlusBossBtn",	 	"Show map boss checkbox", 		280, -172, 	"If checked, a checkbox will be shown on the world map allowing you to toggle boss location buttons.",LeaPlusOptQuests)

		OptionsText("Battlegrounds", 280, -212,LeaPlusOptQuests);
		LeaPlusCheckbox("LeaPlusBGRelease",		"Automatically release", 		280, -232, 	"If checked, you will release automatically after you die in a battleground unless you are protected by a soulstone.",LeaPlusOptQuests)
		LeaPlusCheckbox("LeaPlusShowHks",		"Show Honorable Kills", 		280, -252, 	"If checked, the total number of lifetime honorable kills for your character will be shown at the top of the Honor frame.",LeaPlusOptQuests)

		-- Set defaults button
		LeaPlusButton("LeaPlusDefltQuests",LeaPlusOptQuests,"Set Defaults","BOTTOMLEFT",10,10,130,25,"Resets all the options on this page back to the default settings.")
		LeaPlusDefltQuests:SetScript("OnClick", function() 
			LeaPlusOptionsLC["LeaPlusQuestLevel"]		= "On"
			LeaPlusOptionsLC["LeaPlusQAccHead"]			= "Off"
			LeaPlusOptionsLC["LeaPlusQAccAll"]			= "Off"
			LeaPlusOptionsLC["LeaPlusQAccDaily"]		= "Off"
			LeaPlusOptionsLC["LeaPlusQuestComplete"]	= "Off"
			LeaPlusOptionsLC["LeaPlusQuestFont"]		= "Off"
			LeaPlusOptionsLC["LeaPlusLFGTimer"]			= "On"
			LeaPlusOptionsLC["LeaPlusRaidCheck"]		= "On"
			LeaPlusOptionsLC["LeaPlusLootNoConfirm"]	= "Off"
			LeaPlusOptionsLC["LeaPlusInterruptMsg"]		= "Off"
			LeaPlusOptionsLC["LeaPlusBGRelease"]		= "On"
			LeaPlusOptionsLC["LeaPlusBossBtn"]			= "On"
			LeaPlusOptionsLC["LeaPlusShowHks"]			= "On"
			LeaPlusSetDim()
			LeaPlusOptQuests:Hide();
			LeaPlusOptQuests:Show();
			DoItNow(frame);
			-- Refresh certain frames (to update changes)
			if QuestLogFrame:IsShown() then
				QuestLogFrame:Hide()
				QuestLogFrame:Show()
			end
			if PVPFrame:IsShown() then
				PVPFrame:Hide()
				PVPFrame:Show()
			end
		end)

----------------------------------------------------------------------
-- 	Miscellaneous
----------------------------------------------------------------------

		local LeaPlusOptMisc = CreateFrame('Frame', 'LeaPlusOptMisc', LeaPlusOpt0)
	
		LeaPlusOptMisc.name = "Miscellaneous"
		LeaPlusOptMisc.parent = "Leatrix Plus"

		OptionsTitle("Leatrix Plus",(select(3, GetAddOnInfo("Leatrix_Plus"))),LeaPlusOptMisc);

		OptionsText("Graphics", 16, -72,LeaPlusOptMisc);
		LeaPlusCheckbox("LeaPlusDeathEffect", 	"Hide death effect", 			16, -92, 	"If checked, the death effect (grey glow) will not be shown when you are a ghost.",LeaPlusOptMisc)
		LeaPlusCheckbox("LeaPlusNetherEffect", 	"Hide netherworld", 			16, -112, 	"If checked, the netherworld effect (such as mage Invisibility) will not be shown.",LeaPlusOptMisc)
		LeaPlusCheckbox("LeaPlusSpecialEffect", "Hide special effects", 		16, -132, 	"If checked, special effects (such as the haze effect in Riplash Strand, Borean Tundra) will not be shown.",LeaPlusOptMisc)
		LeaPlusCheckbox("LeaPlusGlowEffect", 	"Remove screen glow", 			16, -152, 	"If checked, the screen glow will not be shown.\n\nNote that checking this option will reduce overall graphics quality, but you can use it when required to hide the drunken haze (blurry screen).",LeaPlusOptMisc)
		LeaPlusCheckbox("LeaPlusZoomOut", 		"Set zoom out to max", 			16, -172, 	"If checked, you will be able to zoom out to a greater distance.\n\nThis can help with lots of encounters where you need to see more of the area around you.",LeaPlusOptMisc)
		LeaPlusCheckbox("LeaPlusGryphons",		"Hide gryphons", 				16, -192, 	"If checked, the Blizzard gryphons will not be shown either side of the main bar.",LeaPlusOptMisc)

		OptionsText("Hunter", 16, -232,LeaPlusOptMisc);
		LeaPlusCheckbox("LeaPlusPetIcon",		"Show Mend Pet icon", 			16, -252, 	"If checked, an icon for Mend Pet will be shown next to the pet frame while Mend Pet is active.",LeaPlusOptMisc)

		-- Set defaults button
		LeaPlusButton("LeaPlusDefltMisc",LeaPlusOptMisc,"Set Defaults","BOTTOMLEFT",10,10,130,25,"Resets all the options on this page back to the default settings.")
		LeaPlusDefltMisc:SetScript("OnClick", function() 
			LeaPlusOptionsLC["LeaPlusDeathEffect"] 		= "On"
			LeaPlusOptionsLC["LeaPlusNetherEffect"] 	= "On"
			LeaPlusOptionsLC["LeaPlusSpecialEffect"] 	= "Off"
			LeaPlusOptionsLC["LeaPlusGlowEffect"] 		= "Off"
			LeaPlusOptionsLC["LeaPlusZoomOut"]			= "Off"
			LeaPlusOptionsLC["LeaPlusGryphons"]			= "Off"
			LeaPlusOptionsLC["LeaPlusPetIcon"]			= "Off"
			LeaPlusSetDim()
			LeaPlusOptMisc:Hide();
			LeaPlusOptMisc:Show();
			DoItNow(frame);
		end)

----------------------------------------------------------------------
-- 	End of options panel
----------------------------------------------------------------------

	-- Add panels to interface options    
	InterfaceOptions_AddCategory(LeaPlusOpt0)
	InterfaceOptions_AddCategory(LeaPlusOptChar)
	InterfaceOptions_AddCategory(LeaPlusOptText)
	InterfaceOptions_AddCategory(LeaPlusOptQuests)
	InterfaceOptions_AddCategory(LeaPlusOptMisc)

	end

	-- 	Show panel
	LeaPlusOpt0:OptionsPanel();

----------------------------------------------------------------------
-- 	World buttons and checkboxes
----------------------------------------------------------------------

	-- Dungeon Finder time button
	local LeaPlusTimer = CreateFrame("Button", "LeaPlusTimer", LFDQueueFrame, "UIPanelButtonTemplate") 
	LeaPlusTimer:SetWidth(40)
	LeaPlusTimer:SetHeight(25) 
	LeaPlusTimer:SetAlpha(1.0)
	LeaPlusTimer:SetPoint("BOTTOMLEFT", 06, 290)
	LeaPlusTimer:SetText("Time") 
	LeaPlusTimer:RegisterForClicks("AnyUp") 
	LeaPlusTimer.tiptext = "Toggles showing your random dungeon cooldown if the rewards window is showing.\n\nThis button has no effect if the rewards window is not showing."
	LeaPlusTimer:SetScript("OnEnter", ShowTooltip)		
	LeaPlusTimer:SetScript("OnLeave", HideTooltip)
	LeaPlusTimer:SetScript("OnClick", function() 
		if LFDQueueFrameCooldownFrame:IsShown() then
			LFDQueueFrameCooldownFrame:Hide();
		else
			LFDQueueFrameCooldownFrame:Show();
		end
	end)

	-- Dungeon Finder 'Choose Your Role' checkbox
	LeaPlusCheckbox("LeaPlusHideRC", "", 40, 290, "If checked, the 'Choose your role' confirmation will not be shown.  You can use this checkbox if someone in your dungeon group is spamming the role confirmation window.\n\nThis setting is not saved between login sessions.",LFDQueueFrame)
	LeaPlusHideRC:SetHitRectInsets(0, 0, 0, 0);
	LeaPlusHideRC:ClearAllPoints();
	LeaPlusHideRC:SetPoint("BOTTOMLEFT",46, 290)

	-- Character frame checkboxes
	LeaPlusCheckbox("LeaPlusCharHelm", 	"Helm",	 56, -276, "",CharacterModelFrame)
	LeaPlusCharHelm:SetHitRectInsets(0, 0, 0, 0);

	LeaPlusCheckbox("LeaPlusCharCloak", "Cloak", 116, -276, "",CharacterModelFrame)
	LeaPlusCharCloak:SetHitRectInsets(0, 0, 0, 0);

	CharacterModelFrame:HookScript("OnShow",function()
		if LeaPlusOptionsLC["LeaPlusPlayerCharTog"] == "On" then
			if ShowingHelm() then
				LeaPlusCharHelm:SetChecked(true)
			else
				LeaPlusCharHelm:SetChecked(false)
			end
			if ShowingCloak() then
				LeaPlusCharCloak:SetChecked(true)
			else
				LeaPlusCharCloak:SetChecked(false)
			end
		end
		-- Lock checkboxes if you are dead or a ghost
		if UnitIsDeadOrGhost("player") then
			LeaPlusCharHelm:Disable()
			LeaPlusCharHelm:SetAlpha(0.3)
			LeaPlusCharCloak:Disable()
			LeaPlusCharCloak:SetAlpha(0.3)
		else
			LeaPlusCharHelm:Enable()
			LeaPlusCharHelm:SetAlpha(1.0)
			LeaPlusCharCloak:Enable()
			LeaPlusCharCloak:SetAlpha(1.0)
		end
	end)

	-- World map boss checkbox
	LeaPlusCheckbox("LeaPlusMapBoss", 	"Boss",	 -230, 0, "qqq",WorldMapQuestShowObjectives,true)
	LeaPlusMapBoss:SetHitRectInsets(0, -28, 0, 0);
	LeaPlusMapBoss:SetSize(24, 24)

	WorldMapFrame:HookScript("OnShow",function()
		if LeaPlusOptionsLC["LeaPlusBossBtn"] == "On" then
			if WorldMapBossButtonFrame:IsShown() then
				LeaPlusMapBoss:SetChecked(true)
			else
				LeaPlusMapBoss:SetChecked(false)
			end
		end
	end)

	LeaPlusMapBoss:SetScript("OnEnter", function(self)
		WorldMapTooltip:SetOwner(self, "ANCHOR_LEFT")
		WorldMapTooltip:SetText("If enabled, you will be able to look at your map to see boss locations (if available).", nil, nil, nil, nil, 1)
	end)

	LeaPlusMapBoss:SetScript("OnLeave", function(self)
		WorldMapTooltip:Hide()
	end)
